// 自定义promise构造函数
class Promise{
    promiseState = 'pending'
    promiseResult = null
    constructor(callback){
        
        // 特性1：进行中 意味着要调用 
        const resolve = (data)=>{
            if(this.promiseState != 'pending') return
            this.promiseState = 'fulfilled'
            this.promiseResult = data
        }
        const reject = (data)=>{
            if(this.promiseState != 'pending') return
            this.promiseState = 'rejected'
            this.promiseResult = data
        }
        callback(resolve,reject)
    }
}
Promise.prototype.then = function(successCallback,errorCallback){
    if(this.promiseState === 'fulfilled'){
        successCallback(this.promiseResult)
    }
    if(this.promiseState === 'fulfirejectedlled'){
        errorCallback(this.promiseResult)
    }
}
Promise.prototype.catch = function(){}
Promise.prototype.finally = function(){}
Promise.resolve = function(){}
Promise.reject = function(){}
Promise.all = function(){}
Promise.race = function(){}
Promise.allSettled = function(){}
Promise.any = function(){}

// 1.先用
const p = new Promise((resolve,reject)=>{
    resolve(11)
    reject(22)
})
p
    .then(
        res=>{
            console.log('res',res);
        },
        err=>{
            console.log('err',err);
        }
    )